<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>OpLog Server</title>
	<link rel="stylesheet" href="../js/easyui/themes/bootstrap/easyui.css">
	<link rel="stylesheet" href="../js/easyui/themes/icon.css">
	<link rel="stylesheet" href="../css/index-ui.css">
	<script type="text/javascript" src="../js/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="../js/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../js/ams.util.js"></script>
	<script type="text/javascript" src="../js/webapi.js"></script>
	<script type="text/javascript" src="../js2/loginCookies.js"></script>
</head>
<body onload="page_init()">
	<div class="alarm-page-search">
		<ul>
			<li>
				<span>User：</span>
				<input class="easyui-textbox" id="op_userName" type="text" style="width: 80px;"/>
			</li>
			<!-- <li>
				<span>Equipment：</span>
				<input class="easyui-textbox" id="op_eqName" type="text" style="width: 90px;"/>
			</li> -->
			<li>
				<span>Type：</span>
				<select class="easyui-combobox" id="op_type" name="state" style="width:100px;" editable="false" panelHeight="auto">
					<option value="all">All</option>
					<option value="user">User</option>
					<option value="config">Config</option>
					<option value="dummy">Dummy</option>
					<option value="recipe">Recipe</option>
				</select>
			</li>
			<li>
					<tr>
						<span>Time：</span>
						<td>
							<input class="easyui-datebox" id="op_StartDay" style="width:100px;" data-options="sharedCalendar:'#cc'">
						</td>
						<td>&nbsp;~&nbsp;</td>
						<td>
							<input class="easyui-datebox" id="op_EndDay" style="width:100px;" data-options="sharedCalendar:'#cc'">
						</td>
					</tr>
				<div id="cc" class="easyui-calendar"></div>
			</li>
			<li>
				<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="width:80px;margin:0 10px 0 10px;" onclick="onQuery()">Query</a>
			</li>
			<div class="clearfix"></div>
		</ul>
	</div>
	<table id="eq_oplog_grid" class="easyui-datagrid" title="" style="width:100%;height:88%" pagination="false">
		<thead>
			<tr>
				<!-- <th data-options="field:'index',width:70">No</th> -->
				<th data-options="field:'userName',width:150">User Name</th>
				<!-- <th data-options="field:'eqName',width:150">Equipment Name</th> -->
				<th data-options="field:'opType',width:100">Op Type</th>
				<th data-options="field:'opTime',width:200">Op Time</th>
				<th data-options="field:'opContent',width:500">Op Content</th>
			</tr>
		</thead>
	</table>
	<div id="oplog-pag-svr" style="background:#efefef;border:1px solid #ccc;"></div>
</body>

<script language="javascript"> 
var eqn = null;
var count = 1;
function page_init()
{
	$('#oplog-pag-svr').pagination({
		pageSize:30,
		layout:['list','prev','manual','next']
	});
	
	$('#eq_oplog_grid').datagrid({
	//rownumbers:'true',
	singleSelect:'true',
	lines:true,
	clickToEdit: false,
	dblclickToEdit: false,
	loadMsg: 'Loading Data ......',
	pagination : false,
	pageSize : 30,
	method:'get'
	});
		
	on_refresh_log_content(1, 30);
}

$('#oplog-pag-svr').pagination({
    pageSize:30,
    afterPageText:'',
    displayMsg:'',
    onSelectPage:function(pageNumber, pageSize){
    	$(this).pagination('loading');
	    on_refresh_log_content(pageNumber, pageSize);
		$(this).pagination('loaded');
	}
});

function on_refresh_log_content(pageNumber, pageSize)
{
	if (ams_is_sim_mode()) {
	 	$.getJSON('oplog_server.json', function(json_data) {
			$('#eq_oplog_grid').datagrid({
				data:json_data
			})
		})
	} else {
		var eqn = get_page_param('eq');
		$.ajax({
			type: 'POST',
			contentType: 'application/json',
			url: getWebServiceUrl("getUserOpLogs"),		
			data:JSON.stringify({
				"userName":$("#op_userName").val(),
				"eqName":eqn,
				"opType":$("#op_type").val(),
				"stDay":$("#op_StartDay").val(),
				"edDay":$("#op_EndDay").val(),
				"opIndex":(pageNumber - 1) * pageSize,
				"count":pageSize
			}),
			dataType: 'json',
			success : function(datas) {
				console.log(JSON.parse(datas.d));
				$('#eq_oplog_grid').datagrid('loadData',JSON.parse(datas.d));
				if(JSON.parse(datas.d).length == pageSize){
          count += pageSize;
          $('#oplog-pag-svr').pagination({
					total:count
					});
				}
			},
			error: function (error) {
				console.log(error) 
			}
		});
	}
}

function onQuery(){
	count = 1;
	$('#oplog-pag-svr').pagination({
		pageNumber:1,
		layout:['list','prev','manual','next']
	});
	on_refresh_log_content(1, 30);
}

$.fn.datebox.defaults.formatter = function(date){
	var y = date.getFullYear();
	var m = date.getMonth()+1;
	var d = date.getDate();
	return y+'-'+m+'-'+d;
};

$.fn.datebox.defaults.parser = function(s){
	var t = Date.parse(s);
	if (!isNaN(t)){
		return new Date(t);
	} else {
		return new Date();
	}
}
</script>
</html>
